/* 1960 */

clear
use "$sourcedatadir/se/VU_1960 SND_0861/0001en.dta"
do "$scriptsdir/se_prepare1960.do"
save "$gendatadir/se_1960.dta", replace


/* 1964 */

clear
use "$sourcedatadir/se/VU_1964 SND_0007/0007us.dta"
do "$scriptsdir/se_prepare1964.do"
save "$gendatadir/se_1964.dta", replace


/* 1968 */

clear
use "$sourcedatadir/se/VU_1968 SND_0039/0039us.dta"
do "$scriptsdir/se_prepare1968.do"
save "$gendatadir/se_1968.dta", replace


/* 1970 */

clear
use "$sourcedatadir/se/VU_1970 SND_0047/0047us.dta"
do "$scriptsdir/se_prepare1970.do"
save "$gendatadir/se_1970.dta", replace


/* 1973 */

clear
use "$sourcedatadir/se/VU_1973 SND_0040/0040us.dta"
do "$scriptsdir/se_prepare1973.do"
save "$gendatadir/se_1973.dta", replace


/* 1976 */

clear
use "$sourcedatadir/se/VU_1976 SND_0008/0008us.dta"
do "$scriptsdir/se_prepare1976.do"
save "$gendatadir/se_1976.dta", replace


/* 1979 */

clear
use "$sourcedatadir/se/VU_1979 SND_0089/0089us.dta"
do "$scriptsdir/se_prepare1979.do"
save "$gendatadir/se_1979.dta", replace


/* 1982 */

clear
use "$sourcedatadir/se/VU_1982 SND_0157/0157us.dta"
do "$scriptsdir/se_prepare1982.do"
save "$gendatadir/se_1982.dta", replace


/* 1985 */

clear
use "$sourcedatadir/se/VU_1985 SND_0217/0217us.dta"
do "$scriptsdir/se_prepare1985.do"
save "$gendatadir/se_1985.dta", replace


/* 1988 */

clear
use "$sourcedatadir/se/VU_1988 SND_0227/0227us.dta"
do "$scriptsdir/se_prepare1988.do"
save "$gendatadir/se_1988.dta", replace


/* 1991 */

clear
*use "$swedir/SND/VU_1991 SND_0391/0391us.dta"
use "$sourcedatadir/se/snes1991.dta"
do "$scriptsdir/se_prepare1991.do"
save "$gendatadir/se_1991.dta", replace


/* 1994 */

clear
*use "$swedir/SND/VU_1994 SND_0570/0570us.dta"
use "$sourcedatadir/se/snes1994.dta"
do "$scriptsdir/se_prepare1994.do"
save "$gendatadir/se_1994.dta", replace


/* 1998 */

clear
use "$sourcedatadir/se/VU_1998 SND_0750/0750us.dta"
do "$scriptsdir/se_prepare1998.do"
save "$gendatadir/se_1998.dta", replace


/* 2002 */

clear
use "$sourcedatadir/se/VU_2002 SND_0812/0812us.dta"
do "$scriptsdir/se_prepare2002.do"
save "$gendatadir/se_2002.dta", replace


/* 2006 */

clear
*use "$swedir/SND/VU_2006 SND_0861/0861us.dta"
use id SND_* VU06* using "$sourcedatadir/se/SNES_2010_panel_2006_2010 SND_0925/Svensk valundersikning 2006-2010 panel.dta"
do "$scriptsdir/se_prepare2006.do"
save "$gendatadir/se_2006.dta", replace


/* 2010 */

clear
*use "$swedir/SND/SNES_2010_panel_2006_2010 SND_0925/Svensk valundersîkning 2006-2010 panel.dta"
use id SND_* VU10* using "$sourcedatadir/se/SNES_2010_panel_2006_2010 SND_0925/Svensk valundersikning 2006-2010 panel.dta"
do "$scriptsdir/se_prepare2010.do"
save "$gendatadir/se_2010.dta", replace


/* Merging */

clear
use "$gendatadir/se_1960.dta"
keep $keepers1960
append using "$gendatadir/se_1964.dta", keep($keepers1964) nol
append using "$gendatadir/se_1968.dta", keep($keepers1968) nol
append using "$gendatadir/se_1970.dta", keep($keepers1970) nol
append using "$gendatadir/se_1973.dta", keep($keepers1973) nol
append using "$gendatadir/se_1976.dta", keep($keepers1976) nol
append using "$gendatadir/se_1979.dta", keep($keepers1979) nol
append using "$gendatadir/se_1982.dta", keep($keepers1982) nol
append using "$gendatadir/se_1985.dta", keep($keepers1985) nol
append using "$gendatadir/se_1988.dta", keep($keepers1988) nol
append using "$gendatadir/se_1991.dta", keep($keepers1991) nol
append using "$gendatadir/se_1994.dta", keep($keepers1994) nol
append using "$gendatadir/se_1998.dta", keep($keepers1998) nol
append using "$gendatadir/se_2002.dta", keep($keepers2002) nol
append using "$gendatadir/se_2006.dta", keep($keepers2006) nol
append using "$gendatadir/se_2010.dta", keep($keepers2010) nol


// Based on SM's inspection, the socref variable has different intervals in some years.
// Standardizing across all years.
recode  socref .25=.3333333 .75=.6666667
replace socref=.3333333 if socref>0 & socref<.5

gen     class3 = class_reho_3cat
replace class3 = class_resp_3cat if class3 == .
replace class3 = class_husb_3cat if class3 == . & male == 0 & married == 1
replace class3 = class_spou_3cat if class3 == . & male == 0 & married == 1
replace class3 = class_reho_3cat_strata if class3 == .
recode  class3 50=. 88=.

gen     unioninfluenced = 1 if unionmem_resp == 1 | unionmem_spou == 1
replace unioninfluenced = 0 if unioninfluenced == . & (unionmem_resp != . | unionmem_spou != .)

save "$gendatadir/se_cdf.dta", replace
